from selenium import webdriver
import time
class login:

    def login(self):
        '''登录后台'''
        driver= webdriver.Firefox()
        driver.get("http://localhost/TinyShopv2.4/admin")
        driver.maximize_window()
        #登录成功
        time.sleep(3)
        driver.find_element_by_name('name').clear()
        driver.find_element_by_name('name').send_keys('admin')
        driver.find_element_by_name('password').clear()
        driver.find_element_by_name('password').send_keys('123456')
        driver.find_element_by_name("verifyCode").send_keys("aaaa")
        driver.find_element_by_xpath('/html/body/div/div/form/ul/li[4]/input[1]').click()
        time.sleep(3)
        cookies = driver.get_cookies()
        _cookies = {cookies[0]['name']:cookies[0]['value']}
        return driver,_cookies

    def loginFre(self):
        '''登录前台'''
        driver =webdriver.Firefox()
        driver.get("http://192.168.0.13/TinyShop_v2.4/index.php?con=simple&act=login")
        driver.maximize_window()
        time.sleep(3)
        driver.find_element_by_name("account").send_keys("user1@qq.com")
        driver.find_element_by_name("password").send_keys("123456")
        driver.find_element_by_xpath("/html/body/div[2]/div/div/form/ul/li[4]/button").click()
        time.sleep(3)
        return driver

if __name__=="__main__":
    a=login()
    a.login()
    a.loginFre()
